package main
{
	import com.darwin.darwinDll.Dll;
	import com.darwin.darwinUI.core.IUISkinAdapter;
	
	import flash.display.DisplayObject;
	
	/**
	 * 皮肤代理加载
	 * @author lipi
	 */
	public class AppSkinAdapter implements IUISkinAdapter
	{
		public function AppSkinAdapter()
		{
		}
		
		
		public function getSkin(skinName:String, fn:Function=null):DisplayObject
		{
			var clazz:Class = getClass(skinName);
			var displayObject:DisplayObject = new clazz() as DisplayObject;
			var $data:Object = {};
			$data[skinName] = displayObject;
			fn($data);
			return displayObject;
		}
		
		public function getSkinClass(skinName:String, fn:Function=null):Class
		{
			var clazz:Class = getClass(skinName);
			var $data:Object = {};
			$data[skinName] = clazz;
			fn($data);
			return clazz;
		}
		
		private function getClass(skinName:String):Class
		{
			var sArr:Array = skinName.split(".");
			var key:String;
			var subKey:String;
			if(sArr.length > 1)
			{
				key= sArr[0];
				subKey = sArr[1];
			}else{//如果数组为0，数组第一项表示subKey 
				key= "";
				subKey = sArr[0];
			}
			var clazz:Class = Dll.getInstance().getSynPreloadRes(key,subKey);
			return clazz;
		}
		
	}
}